package com.lemon.exam.common.entity.vo;

/**
 * SSE消息视图对象
 *
 * @param type    消息类型 1:心跳消息 2:通知消息 3:其他消息
 * @param success 是否成功
 * @param code:   状态码
 * @param data:   消息
 * @author Lemon
 * @since 2025/10/19 11:52
 */
public record SSEMessageVO(int type, boolean success, int code, Object data) {
    public static SSEMessageVO data(Object data) {
        return builder(2, true, 200, data);
    }

    public static SSEMessageVO heartbeat() {
        return heartbeat("heartbeat");
    }

    public static SSEMessageVO err(int code, Object data) {
        return builder(3, false, code, data);
    }

    public static SSEMessageVO heartbeat(Object data) {
        return builder(1, true, 200, data);
    }

    public static SSEMessageVO builder(int type, boolean success, int code, Object data) {
        return new SSEMessageVO(type, success, code, data);
    }
}
